improve

const correctness
add more tests
fix bugs