sorry for the late reply. The code is in python and ugly, but I could share some key parts, if you like.