extract magic numbers and duplicate code to private method