fix and added error handling