Refactored out the cast code into CastManager class