Small bugfixes and file reorganization