Refactored all the type stuff.
Removed all Ptr-specific types, to use system of flags instead.