Fixed Cannot call method "error" of undefined error

Fix for #14 as reported and fixed by @jnik.