fix some major bugs and resolve issue #4