Tightened function dependencies
Added replace-nil function