tweaked code of last commit