A little clean-up, prepare for storage and error handling