add photodetecter and bug fixes