modernized, added tests