Some bugs left. Main code is here