Made ncd use functions to better effect

This has increased the source code without adding any real benefit

Consider avoiding this, and not merging this into master