added better comments, moved regex function call to drastically increase efficiency