adds better error handling