Fix dist function