Issue #23: fix read-past-end error