Removed redundant bool(), renamed local variables to me more meaningful, and wrote a test to validate string is protected on replace.