refactored some really bad code