Fixed an INSANE bug in the util module.
Various fixes and improvements.