Fix: bugs reported by scrutinizer