More fixes and improvements, still plenty of WTF floating around in there...