Modified so that createdAt is set if its not already present