Fixed bug that caused class cast exception