code  format
some refactorings