fixed retain cycle and refactoring