Added run code, and several bugs.