Selfmade Tilt compensated Compass Pitch, Roll, Yaw

I've been trying to get this code to work for the last week, with the sparkfun magnetometer mentioned and a wii nunchuk. I can't for the life of me get it working. The closest I've come is getting compensation in one direction, but even then it was a variation of around 10 degrees. I'm using the WiiChuck class to get roll and pitch degrees and converting them to radians for use in the rest of the class. Thanks for any help.