fixed some non-working code, not all, and added comments