More tests and bug corrections