fix compilation errors and further improvements