refactor errorhandler for more flexibility
fix and refactor some tests