Refactor rope cod