fixed bug in writing objects