More logical flow and better comments, still with bug