Some refactorings. Implemented downloas state.