Added log-var function for debugging.
Fixed a few minor bugs.