refactor code

fixed some bugs in this simple memory excercise