B various fixes

Contains four bug fixes: #141, #266, #271, #274. See the description of the bugs for the details on what was going wrong.