Fix compile errors and tests