finished main doctor functionality