split magic system into multiple files

this is a long-due fix for the magic system