Corrected a major bug in SPI function