cleaned up source code and improved schematic.