add logger, better algorithm (far from good but it's improving