Cleaned up some error handling