Add tests and fix bugs in files.go