[fix] add logic and tests