better error handling, working