Fixed end-of-string bug. Thanks to Paul Barker for reporting this.