exception handling and other improvements