Refactored code to add posts via AJAX / JS