Working version with log