Code cleanup and additional debugging.