Added function to write data to InfluxDB and fixed other bugs