Added first version of error handling