edited code to deal with code review comments