Some cleanup, added basic sorting