slight changes in errorhandling
code cleaning