added lots of unit tests and improved rendering speed