Removed loops to optimize for speed.