added std:: to a lot of locations which where
missed and #undef'ed min and max where needed.