Some refactoring and cleanup, extra console output