Better error handling in script