Cleanup and error handeling