fix type mismatch on comparison at line 110, refactor variable names to be more explicit