Updated database sql and billing function.