Big cleanup + small bugfix