CR change: used String.charAt() instead of String.lastIndexOf() because of performance reasons