bugfix and partial impl of issue #4