Bug fixing and regex optimization. Will clean up regex next