fix formatting and minor bugs