More tests and assertions. Some bugs fixed