Adds better error throwing for edge cases

- Includes tests
- Conforms to strict mode
- Remediates global scope pollution