added a few extra stuff to possibly make this run faster on the CPU