refactored posts controller