Bug fix to prevent buffer from being overwritten