Fixed some major issues reported by Sonar.
Merge pull request #198 from wosiu/master

Fixed last critical and some major issues reported by Sonar.