minor bug fixes and exception handling.