Little refactoring and bugfixing

Missed an import