Added more support for testing, some bug fixes