refactored logging in for higher performance