Added option to access elements by reference, output is sorted, added comments