Refactored code 1/2

Including design document