fixed script order, added file type checking