Added PHI function
Added global error calculation
Removed commented code