Addressed more Vinod's comments and fix test bugs.