Added some type annotations, and added a new (commented) implementation for inplace!.