write more functional-programming-ly (maybe slightly too much?)