Added internal error handling