Remove test classes from installed jar, remove code duplication and some other minor fixes

This is my suggestion for fixing issue #76 and issue #77.