Fixes and refactors log functionality