Code cleanup
Included fixes made to linux branch.