Initial ugly but working version