bugfix and refactoring, code simplified