Code clean up and fix according to Paul's review