Added functionality to validate posts and refactored some code to handle error messages