Issue #42: working version (needs cleanup)