use declare for forward reference
actually just remove nils
some improvements suggested by kibit