corrected the add function and other small mistakes