Added better exception handling.