Tests added and bug fixed