Refactor cap files