Fixed mysterious casting bug