This is the first round of fixing the code based on the scrutinizer report