Added debug argument, improved file parsing