Fix compilation errors + code clean up