separate libraries from hldsv8.cpp
error handling and some optimization