some generic typecasts and further minor changes.