code cleanup
add unit test