edited error handling