fixed pointer arithmetic errors