Cleaned up code, and attempts to use better error handling