fixed egpRemove not working in some situations

fixed egpRemove not working properly if used before the object has been
sent to the client, or if you attempt to create an object with that id
just after using egpRemove. Thanks to avalice for finding the problem.

Fixed egpOrder & some others returning 0 instead of -1 when the object
is invalid.