Modified debugging output to refresh every couple of seconds
Various bugfixes and cleanup.