fixed regex, and various small bugs