Made use of isObject helper function per feedback.