Add better handling of initial memory state
Fix bug in order comparision