Some tests added, bugs fixed