I think we can do this a lot more simply. Just check to see if `filename` ends with `"." + extension`. (Good idea changing the signature of this function.)