Legacy code bug fixes