adding unit tests, and fixing a bug in undefined handling