refactored code and oojsed