Fixed table sorting issue, cleaned up code, fixed an initialization problem with the local storage