Fix cast exception and complete a test