Refactoring: Use minmax function