Regex fix and code cleanup