Fixed memory problem. MAXN can be increased to whatever :D Lost a little speed tho...