better handling of exceptions
print sorted memory
memory only prints on demand