Refactor Ruby codebase