refactored; code runs