Add base controller and remove duplicate code