Updated logic. Still not finished.