Update documentation, improve logic.