Improve runtime from 15m to 3s using booleans instead of ints