added logic for stage