Hacked to get it to work - still very rough working model