Metastability and polarization effects in a pn heterojunction device due to deep states