Adds better error handling