core: refactor file() a bit.