Fixed an off-by-one error in generator.py and added some argument range checks