Added regular expressions to make the function generic
Added additional variables