Bug fixes and changes to casting. Added Object:instanceof.