flexible match tested to work. minor bug fixes