cleaned up p1 scala