Fixed compile errors, added some comments