fixed some pep errors
fixed logic error caused by wrong variable name