move replace_schedule impl to lua