refactored code, added some things