Refactored controller code. Moved common code to base controller