use python logging library instead of print statements for debugging output

plus some minor bug fixes