Fix tests

- Fixes broken functionality when replacing already busted files
- Refactoring