improved file handling a lot