fix formatting and generalize