Moving session time check up inside the while loop