Try going through these topics:
Edit: @Petras_Vestartas did a bunch of work on this a long time ago, he might help too: