Fix memory overwrite error introduced in the last two commits