remaking the loopFunction behavior