code refactor, removed unused var's and helper function.