Refactor init function for easier testing

Signed-off-by: Sharif Olorin <sio@tesser.org>