Rearchitected code to increase stability.