refine
add tests, now buggy