Add missing free in case of an error.
Implement adding and removing methods.