Program Logic moved to separated file (core.py)

Some functions had to be changed due to session handling between the
files.

There was also a teardown_request function added for better SQL session
handling.