Added char by char version - now works well