Copied few bug fixes from original weblocks source