Refactor to preserve order