made changes to do better error handling