modified error handling, minor changes