refactored and partially implemented logging