Duplicate logging is solved. This is the final working version with all
uncleaned code.