Edited error handling