added aditional boolean check inside setTimeout because clearTimeout doesn't seem to be working correctly