implemented write chunk