Refactory

I still need to add some comments to code and do some minor changes. 

@m1ch1 if you have time, you could also take a look how it looks like.