fixed mutex locking issues (called mutex_init)
Also, locked output function to avoid threading issues....