more unit tests. fix some issues