Documentation and some bug fixes