Semi latest changes
Re-implemented generator. Not finished yet