merge with jlee and did some improvements