bugfix & code refactor