Improve logic, documentation.