Fix errors, add new functions