Tests added and bugs fixed