Fixed #133, some code issues discovered by PVS-Studio