Final code. Adequate tests(?)