Refactored code for readability. Fixed a minor runtime error that caused posts to be saved multiple times.