Refactor stuff into tpm