Optimize and simplify isFunction and isObject