added automatic detection of API version