a few fixes and code for db interaction

will move code from the script repo later