Fix bug 3011 which was introduced because of a merge error. Also fixed some flake8 issues

Change-Id: Ib94f91a800ec82ce5286bfe5508c6f95a41be22f