Rebased some code, fixed some names.