Refactor ajax dream controller