Refactor code structure