Working

But very ugly code.