updated the code to 1-liner statements 

using typeof instead of 2 if checks.