Move high-level logic to separate file, also start implementing option to dump only needed tables