Fixing Algorithm. Adding interaction with plot