isn't handling multiple files in the directory properly, adding some debug and first hack at fix