Updated tests and fixed bugs