modify algorithm for testing memory