Issue #106.
Not tested. It also propts to simplify the code further.