Merged fix for #8, rewrote lastIndexOf