Refactored code re: index.php and edit_post.php