Fixed various potential bugs and compiler warnings
Merge pull request #355 from HomerSp/master

Potential bug fixes and compiler warnings