refactored code up to removing blanks