removed unnecessary state variables, since we're using generator; fixed bug