added mag function
added cube IO