fixed sorting on output and added comments