Fixed resetting and cleaned up more code