bug fixes from legacy code