reformats code and adds tests for controller