Horrible hack for assignment3 part3, should not use a temporary file