code cleanup + optimalization