Better documentation and simplified logic