Code cleanup and debugging