Several bug fixes and linking OpenCV libs according to debug/release