Removed old code, added better error handling.