adding tests; tiny refacrtoring