Working version -- heavy changes to follow