Reworked the getFile function