full solution working