add import function, various bugfixes