New tests and bugs fixed