Refactored, logging working.