Fixed last PR and added a test for it