fixed up bug. added regression tests