bugfixes and cmake tuning