Added quantization Functionality

Also fixed array index out of bounds problem.