Adds test and bug fix