Updated working code.