Fixed feedback function (and also some code from martin added)