Bug fixes

merge the branch back to develop as discussed.