Command Line Interface

Added a lot to the command line interface, fixed and optimized some
code. Fixed !=null checks on database connection. Added testing to the
command line.