Refactored posts controller