a bit of refactoring: encapsulated files operations onto class and got rid of procedure-style operations.