Attempt to fix #1576 & #1627

I *think* this should solve these problems.

Not sure if this will affect anything else, but I don't think it does.