Fix bug in writing yaml