A few bug fix for refactor and plotting