Code Tweaks and Added an Additional Check