tweaked code a bit