a full solution with bad performance