Added rudimentary exception handling.