Working generate script, completely automated now