parses arguments, also opens/closes database