Added on/off functions. Cleaned up the code.