rewrite of comment removal code

Here's a fix to clean up the comment removal code. Should be more efficient than the previous version.