I think this could be cleaner within a defered function instead of putting it at every error return.