fix reference bugs; fix logic bugs; update README.md