abstracting database into its own file, sessions into a class, adjusting...

... main to reflect changes