Merged in some improvements from philandstuff
Removed another cond for an if. Makes the compiler happy