code above is used twice in this class