#838: Refactor code