Cleaned up a whole bunch of code and simplified the arduino code.