refactor & bugfix system