Refactored and fixed some bugs

We will have to test the post js render partials on the live server, but this should help clean up the code base.