Removed some redundant casts. Added missing type definitions.