small refactor, reduce some duplicated code