Fixed some typehinting and reuse some helper function.

Signed-off-by: crynobone <crynobone@gmail.com>