fixed errors WITH refactored code