Fixes and an addition.

Sorry for the unclear amount of what has been changed.
Sometimes it works correctly, other times (as you can see) not.