some bug fixes
add tests