Bug fixes to correct regex and remove undefined variables