Fixed some stability issues and improved generation speed by removing
some unnecessary code