implemented magic carpet sort of