Move functions into deduce

Encapsulate helper functions into deduce