What I've shown in the diagram is an inverting amplifier, which is working fine. I have tried putting a voltage follower between the inverter and the comparator, which didn't solve the problem. Ive also tried putting a non-inverting amplifier between the inverter and the comparator, and the output of the amplifier was the same as what i am getting out of the comparator.