Fix npe when no custom params and more...

I was going to fix a NPE but, while I was at it, I also simplified/fixed/refactored a couple of things.