rearanged and added tests
Fixed conflicts