big refactor to use filter and map functions instead of traditional for loop