Refactor based on additional review comments.

Add test cases. Currently tests fail because there's a problem with
using bytes.Replace that needs to be fixed.