Tweaked code a bit