Fix invalid memory read