Fix compile errors and incorrect variables