Tilt compensating a HMC5883 compass with a MMA7455 Accelerometer

With my code, it gives a heading for direction, but when the compass tilts a little, the readings change and become inaccurate. For example if its facing north and you tilt it to the side, it will read west.

im asking for advice on how to read from the accelerometer, and use that data to compensate the reading from the tilt