refactoring and debugging
refacored and debugged