Solved problem 3. Added prim functions.