refactoring of posts controller