create_element function added to DRY code