attempt to refactor to funcational (broken)