fixed unit tests and improved generation logic