some error handling
minor improvements