sr: code refactor and style fix