Fix logics and tests