Tests updated and bugs fixed