Remove code duplication and static arrays