fixed ajax callback and refactored controller