bug fix on distribute function