Many fixes and new functionality