Add tests and fix bug for empty files