using pin results - rewrite; code reorganization