improved memory test and fixed some bugs