Total refactor to make file handling easier