fixing edge cases

counts undefined and empty strings properly