Replaced halfbaked logging with python's logging module. Cleaned up code a bit. Handling error messages a bit better.