removed some unused funcs, refactored some for loops