Cleaned up error handling and removed named return values