Fixed #446 fixed #445 and other minor fixes