fixed writing onto db