re-factored/optimized code and fixed issue after run CodeIt.Right code analysis tool.