Internal bug fixes