Updated mag code to work from any axis