optimise conditional performance
reduce sort() memory overhead in some cases
reduce function call overheads
improve abstraction