updated to use functions rather than functionally run through