Bugfixes to magic system