Optimization fix

Now program works faster