refact and tests
refact and tests