Code review and bug fix