More code cleanup and tweaking