refactored handling of formats