Starting to refactor custom_posts.php for style, code quality, and documentation