added support for duplicate characters