Add more db commands; Rewrite the script to make it more robust