updated add method to handle edge case