Added utility code and made other small changes.