Refactored controller and added some extra tests