remove unreachable code
add tests for some special cases