Refactor before_save callback