Tested code, small bugfixes