Implement new memory check and an invert sort logical