Various bugs and fixes

Did this answer your question?