Cleaner implementation of issue #23