General improvements, smaller refactorings

avoid casting, string switches....