Tests added and some bugs fixed.