Bugfix

all bugfixes an branch bugfix, original code in master.
Every bug in separate commit.