fixed regex and tidying code