(somewhat) working code