Adding some better error handling.