- added proper error handling