Eliminated deep-copy, unnecessary sort + refactored code