writing data on struct, added counter to write on proper position