Pulled out code for controller into seperate file