Rewrite to accomodate latest version of substr