implement formation
some refactoring