Optimised calculations by using vector arithmetics instead of loops.