fixed unevaluated function and removed defensive coding