Error handling and basic clean up