Facts uploading and some refactorings       l

I can split to more PRs if you want to discuss refactorings separately. The first refactoring fixes code duplication. Second is some syntax cleanup (and thing to discuss)