some fixes/cleanup as suggested by @j2sol