more work on case ajax and refactor