made local vars where possible