math: moved some methods to cpp files, traits to visiting