Moved main backend code to controllers