code cleanup and basic improvements