Removed typeof undefined check to fix #1. Adds tests.