Fix issue with type casting exception