Cleaned up sub and gsub problems. Used regex where helpful. Fixes Issue #112.