Not sure which part of the above you’re having problems with but do consider the following, all pseudoscript: