extract out ast cleanup for equality comparison