Refactored ajax and added register controller