better logic and more test