reviewed and found many flaws, added notes for general fixes