Replaced the type cast (twice with 'is) with better syntax (once with 'as')