refactore several places