Imprived version and fix for undefined vars