A cyclic timer program with input dependent condition

You didn't mention it in your problem description, but are you waiting the requisite 90 seconds your code requires before doing anything with the relay?