Code clean up, two bug fixed pending