Many improvements and bug fixes