updated for use with new circuit design. input/output error fixed(finally)