bug 978: Move things around (common functions moved to a lib file)