Basic algorithm working