Added basic exception handling.