Further refined tests and made some small improvements.