Fix improper handling of nil operand.
Add unit tests.