Code cleanup and fixed security flaw.