Added documentation, a few fixes too