Better version detection, some minor fixes