refactor: do not use dynamic allocation where not needed
fix: malloc error handling
feat: add structure for dynamic file access