added more local vars and got rid of cruft.