Added better error handling.