Works fine except double precision out of memory error