code duplicates moved into separate method