Added logging functionality, CLI options, minor debugging