Updated code with small tweaks