Added some Error Checking and Handling