Refactor posts.js.