Algorithm might be semi-working now