Documentation and some code improvements