refactored variables and improved style of code