Fixed class casting issues