There are several things going on in that code. The first step might be resolving the mix of sequential and functional type syntax. May e take a read here and see if that helps clear some things up?
Ugh, Discourse showed me this as a related thread and I didn’t notice how old it was. Sorry to disturb the slumber.