fixed write functionality