not working, but close. Final commit from Nearwoo