Fix off-by-one and indirection bugs
Add newline after printing output