Cleanup error handling and remove dead code