Optimizing code for Digits