fix logic & bugfix