heavy refactorings, split test_contract and fixed error
refactored a little bit