formatted code, implemented some p3 functions