Refactor the code for creating a new post