Code Cleanup, Error handling