now using Regex, updated code style and other minor updates