replaced unnecessary switch & moved file ending check