Refactored to controller, added submit function