added autoUpdate variable and cleaned up code