Added proof of correctness