refactoring done with only a few basic tests