refactored to use ordering