Code cleanup and avoding variable conflicts