#41 forgot to reset a flag
#41 remove some new lines
#41 minor rearrangement