fix minor bugs
add unit tests