Updated code with fixes.