big code-refactor, weird bug