Further rework

- Make file access functions more generic
- Group functions together
- Small additional fixes
Further rework

- Make file access functions more generic
- Group functions together
- Small additional fixes