Cleaned up error handling, added utils