Reduce space complexity