First attempt at making code cleaner and starting on AJAX