refactored code based on pylint analysis