First phase ready, still needs refactorin.