small changes

wrapped the main code in a closure