add proof to justify algorithm to appendix