Fix #245 by removing unwanted units before typechecking