Added JUnit test and made minor changes to allow testing