Refactors Rakefile to avoid some duplication

Fixes clean tasks
[#81992016]