Refactor and clean up save_post_hook