Ported some stuff from old repository