improve logging
add more common code