vectorized loading code, speeding it up and making it more readable.