=authored (hopefully) by myself, here is the first working version