program works, but mem errors