this function looks better than original one, thanks