polished scheduleWrite code