function now accepts dynamic maxChar values