added comments to getCosts main algorithm