Maybe also add a check 
if (!paused) {
  return;
}

To avoid executing this logic if not paused.