add preamble
fix off-by-one references