on_protoctor_error() implemented and some refactoring