This may be interesting for people to read. Just a warning, all AGPL, so using this code snippets will make your source open. Hope you like the reading.