finalized code, testing