prettier code, better error handling