added circuit, fixed minor bugs