fix writing to database
fix centroid calculation