code refactored and comments added
code refactored and comments added