fix character function looping problem