Updated from anarkia's optimization