Refactor and SH buffer fix