Added tests for memory, and fixed bugs