finished tup refactoring