updated after reviewing and debugging