refactored some bad code