LIB: Fix compiler warnings/duplicate code/constness problems