lots of fixes
add tests