added some tests, and some fixes based on them