Code revewi and bug fixes