Simplified logic of extension and fixed issue #2 mentioned in README.md.