much cleanup and make it work for simple cases.