tidy and prune the code