Tidy and remove unused code