Fixing some bugs(as Scrutinizer recommended)