changed data to dat in some functions to avoid confusion when dat doesn't exist