copied from core so we can modify