Refactor some code
Fix preview
Fix behavior detection
Merge branch 'bugfix/bugs' into devel