fixed following function (hopefully)