refactor and significantly cleanup ajax response cycle