made worked algorithm