improved dbinput.py : split into functions