Added a bit more Exception handling.