changed scope of all functions to  + added autoload functionality (untested)