cleaned up generation code a bit