updated to work with new interface. Less code needed and easier to understand.