Fixed sort and cleaning up