I tested it, it didn't work, now it does.

I got rid of realloc in addPtr(), as it was causing issues. Some other
minor changes, add NULL handling to the main method.