refactored. code was duplicated