move error handlers, code style improvements