Documentation, some logic changes