Fixed incorrect perlin 3D calculation
Minor, localized speed improvements and code reorganizattion