minor changes, exception handling changed