Final version

Changed comments and implemented code, tested with test cases from
discussion board