fixed mem out of bounds error