Corrected minor bug and improved regex (could be better)