More logic and tests