Fixed writing and reading for last character