fix index out of range error

See Issue #1