Improved tests, fixed found bugs