Added Mainfunction and fixed some compile errors