add support for traits to the autoloader; optimized the code flow; closes #1680