Fixed patch and added tests