refactor ajax and show functions