Added some comments and type annotations.