Fixed bug and add testing