Refactor post saving code