Lots of updates and fixes (except test case)