rewrote code to see what it's doing
refactored code for clarity