refactor posts controller