Tidy up AMF controller and optimise a few rails things.