Refactor main method and db switch functions
add/revise documentation
bugfixes, rename methods