The main trick happens here.