Add logging and improve init