Fix plugin's hanging. Add more unit tests