made some optical changes and error handling