Fixed some compilation errors
Various improvements