Solved p23 finally, after about 5 rewrites