Fix some problems, code clean-up

Debugging and logging now work well. Some comments removed and
typos fixed.