Working example again - not fully optimized though