Fix shutdown errors, more organization