Various bug fixes and edits