refatoring and more tests.