fixed compiliation errors and run-time errors