Moved some business logic to controller