rearanged and added tests