Trouble shooting the logic