Some refactoring to simplify code and make file helper more versatile