Move matrix code to galaxy class