Here is a new set of functionality for your project,

This new functionality should resolve issue #42. I also added unit tests so that this will work into the future