added checking for the previous string