Fixed #9, some improvements