Some piece of code I found useful - maybe wrongly designed