fixed issue #1, some improvements